package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.web.bind.annotation.*;

/**
 * Rest风格的JSON交互
 *
 *   GET     http://localhost:8080/rest/json  查询
 *   POST    http://localhost:8080/rest/json  添加
 *   PUT     http://localhost:8080/rest/json   修改
 *   Delete  http://localhost:8080/rest/json/{id}   删除
 * @author lixu
 */
@RestController
@RequestMapping("/rest/json")
public class RestJsonController {

    /**
     * 请求 查询
     *    没有请求体
     *    http://localhost:8080/rest/json?id=123&name=xxx
     *    http://localhost:8080/rest/json/123/xxx
     *
     */
    @GetMapping
    public User get(User user){
        //User user = new User();
        user.setName("Rest风格的JSON交互请求 查询");
        return user;
    }
    /**
     * 请求 添加
     */
    @PostMapping
    public User add(@RequestBody User user){
        System.out.println("开始添加");
        user.setName("Rest风格的JSON交互--请求添加 ");
        return user;
    }
    /**
     * 请求 修改
     */
    @PutMapping
    public User update(@RequestBody User user){
        System.out.println("开始修改");
        user.setName("Rest风格的JSON交互--请求修改 ");
        return user;
    }
    /**
     * 请求 删除
     */
    @DeleteMapping("/{id}")
    public User delete(@PathVariable Integer id){
        System.out.println("开始删除:" + id);
        User user = new User();
        user.setName("Rest风格的JSON交互--请求删除");
        return user;
    }
}
